package cn.terminus.biz.customer.contractfile;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractfile.dto.*;
import cn.terminus.data.customer.contractfile.dao.ContractFileDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (ContractFile)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:01:00
 */
@Component
public class ContractFileManager extends AbstractTerminusManager {
    @Autowired
    private ContractFileDao contractFileDao;

    public Integer add(ContractFileNewDto dto) throws DataAccessException {
        try {
            return contractFileDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractFileManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractFileEditDto dto) throws DataAccessException {
        try {
            return contractFileDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractFileManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractFileResultDto> gets(ContractFileGetsDto dto) throws DataAccessException {
        try {
            return contractFileDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractFileManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractFileResultDto> query(ContractFileQueryDto dto) throws DataAccessException {
        try {
            return contractFileDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractFileManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractFileDeleteDto dto) throws DataAccessException {
        try {
            return contractFileDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractFileManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractFileResultDto> page(ContractFileQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractFileResultDto> result = (Page<ContractFileResultDto>) contractFileDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractFileResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractFileManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer insertBatch(List<ContractFileNewDto> fileNewDtoList) throws DataAccessException {
        try {
            return contractFileDao.insertBatch(fileNewDtoList);
        } catch (Exception e) {
            logger.error("ContractFileManager批量添加，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractFileDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("ContractFileManager批量添加，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
